package com.JZ.QM.scheduledTasksService;

import com.JZ.QM.service.NewCombinationYieldService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author: cyc
 * @email cyc@gmail.com
 * @date: 2020/6/29 11:07
 */
@Service
public class NewComShareDailyIncomeService {
    @Resource
    NewCombinationYieldService newCombinationYieldService;

    @Scheduled(cron="0 20 0 * * *")
    public void updateNewComYield(){
        //组合日收益更新的状态
        boolean newCombinationUpdateFlag = false;
        //声明当前的时间
        Date now = new Date();
        //定义时间的格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");//设置日期格式
        //定义日历时间
        Calendar c = Calendar.getInstance();
        //前一天时间
        Date start = new Date();
        //前一天日期格式转换
        String newCombinationUpdateDate="";

        c.add(Calendar.DATE, -1);
        start = c.getTime();
        newCombinationUpdateDate = dateFormat.format(start);

        //获取组合的更新状态
        newCombinationUpdateFlag = newCombinationYieldService.updateCombinationDailyIncomeRadio(newCombinationUpdateDate);
        if(newCombinationUpdateFlag){
            System.out.println("用户修改后的组合已经更新完成");
        } else {
            System.out.println("用户修改后的组合已经更新失败");
        }
    }
}
